package ossFileinfo

import (
	"common/comCopier"
	"common/dao/model"
	"common/mysql"
	"context"
	"file/internal/svc"
	"file/internal/types"
	"github.com/zeromicro/go-zero/core/logx"
)

type UploadInformationLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUploadInformationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadInformationLogic {
	return &UploadInformationLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UploadInformationLogic) UploadInformation(req *types.ChangeSysFileResp) (resp *types.SysFileResp, err error) {
	// todo: add your logic here and delete this line
	var stirs = make([]string, 0)
	stirs = append(stirs, req.UUID)
	datas, err := mysql.FindFileByUuids[model.SysFile](stirs, l.svcCtx.DB)
	if err != nil {
		return nil, err
	}
	data := datas[0]
	data.GroupName = req.GroupName
	err = l.svcCtx.DB.Save(&data).Error
	if err != nil {
		return nil, err
	}
	err = comCopier.CopyWithOption(resp, data)
	return resp, nil
}
